<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>组件之间传递</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <child content="dell"></child>
        <child content="lee"></child>
    </div>
</body>

</html>
<script>
    Vue.prototype.bus = new Vue();

    Vue.component('child', {
        data: function () {
            return {
                selfContent:this.content
            }
        },
        props: {
            content: String
        },
        template: '<div @click="handleClick">{{selfContent}}</div>',
        methods: {
            handleClick: function () {
                this.bus.$emit('change', this.selfContent);
            }
        },
        mounted: function () {
            var _this = this;
            this.bus.$on('change', function (msg) {
                _this.selfContent = msg;
            })
        },
    })
    var vm = new Vue({
        el: "#app"
    })
</script>